package com.jyx.web.udp;

import java.net.*;
public class UDPServer {
	public static void main(String[] args) throws Exception{
		DatagramSocket ds=new DatagramSocket(9000);//服务端口
		while (true) {
			byte[] bs1 = new byte[100];
			DatagramPacket letter1 = new DatagramPacket(bs1, 0, bs1.length);//制作空信封用来收信
			ds.receive(letter1);
			InetAddress address = letter1.getAddress();
			int port = letter1.getPort();
			String str = "北京2008年举行奥运会";
			byte[] bs2 = str.getBytes();
			DatagramPacket letter2 = new DatagramPacket(bs2, 0, bs2.length,address, port);//获得客户端的ip和port然后将信息发给客户端
			ds.send(letter2);
		}		

	}

}